package com.wanxi.controller;

import com.wanxi.model.NavModel;
import com.wanxi.model.ResultModel;
import com.wanxi.service.NavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 杨金乾
 */
@Controller
@CrossOrigin(origins = "*")
public class NavController {
    @Autowired
    private NavService navService;

    @Autowired
    SendMessageController sendMessageController;
    private String table="导航";
    @RequestMapping("/back/nav/add")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")
    protected ResultModel navAdd(NavModel model){
        ResultModel resultModel = navService.add(model);
        sendMessageController.addUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/nav/findAll")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel navFindAll(NavModel model){
//        5.得到返回值
        ResultModel resultModel = navService.findAll(model);
        sendMessageController.findAllUserMessages(table);
//        6.返回给前端
        return resultModel;
    }


    @RequestMapping("/back/nav/isShow")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel navIsShow(NavModel model){
//        5.得到返回值
        ResultModel resultModel = navService.isShow(model);
        sendMessageController.updateIsShowMessages(table);
//        6.返回给前端
        return resultModel;
    }
}
